import openpyxl
import os

"""
翻转电子表格
"""


def exchangeRowsAndColumns():
    wb = openpyxl.load_workbook("../files/openpyxl_read.xlsx")
    sheet = wb.active

    max_rows = sheet.max_row
    max_columns = sheet.max_column
    sheetData = []
    for i in range(1, max_rows+1):
        rowData = []
        for j in range(1, max_columns+1):
            rowData.append(sheet.cell(i, j).value)
        sheetData.append(rowData)

    print(sheetData)
    print(sheetData[1][1])

    wb = openpyxl.Workbook()
    sheet = wb.active
    for i in range(max_rows):
        for j in range(max_columns):
            sheet.cell(j+1, i+1).value = sheetData[i][j]

    wb.save("../files/openpyxl_test3.xlsx")


if __name__ == '__main__':
    exchangeRowsAndColumns()
